package com.lc.recovery.ui.activity.recoverymine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.recovery.R;
import com.lc.recovery.app.AppActivity;
import com.lc.recovery.http.request.AccountInfoApi;
import com.lc.recovery.http.response.AccountInfoBean;
import com.lc.recovery.other.IntentKey;
import com.lc.recovery.util.SPUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AccountBalanceActivity extends AppActivity {
    @BindView(R.id.tv_balance)
    TextView tvBalance;
    @BindView(R.id.tv_chae)
    TextView tvChae;
    private String user_type;
    private String userId;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_accountbalance;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        if (SPUtil.get(this, IntentKey.TYPE,"").equals("1")||SPUtil.get(this, IntentKey.TYPE,"").equals("2")){
            user_type = "1";
        }else if (SPUtil.get(this, IntentKey.TYPE,"").equals("3")){
            user_type="2";
        }else {
            user_type="3";
        }
        userId=SPUtil.get(this, IntentKey.USERID,"");

    }

    @Override
    protected void onStart() {
        super.onStart();
        accountInfo();
    }

    private void accountInfo() {
        EasyHttp.post(this)
                .api(new AccountInfoApi().setUser_id(userId).setType(user_type)).request(new HttpCallback<AccountInfoBean>(this) {

            @Override
            public void onSucceed(AccountInfoBean data) {
                if (data.getCode() == 200) {

                    tvBalance.setText(data.getMoney());
                    if (data.getDescript().isEmpty()){
                        tvChae.setVisibility(View.GONE);
                    }
                    tvChae.setText(data.getDescript());
                }

            }

            @Override
            public void onFail(Exception e) {
//                super.onFail(e);

            }
        });
    }
    @OnClick({R.id.tv_tixianjilu, R.id.tv_yuejilu, R.id.tv_tixian})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_tixianjilu:
                startActivity(new Intent(getContext(),WithdrawalRecordActivity.class).putExtra("user_type",user_type));

                break;
            case R.id.tv_yuejilu:
                startActivity(new Intent(getContext(),BalanceRecordActivity.class).putExtra("user_type",user_type));

                break;
            case R.id.tv_tixian:
                startActivity(new Intent(getContext(),WithdrawalActivity.class).putExtra("user_type",user_type));

                break;
        }
    }
}
